Plot Kalmia locations in ggmaps
library(ggmap)
## Loading required package: ggplot2
kaml <- read.csv("/Users/cswitzer/Dropbox/ExperSummer2016/Kalmia/Revision1_AmNat/Supp_File_1_kalmiaAccessions.csv")
lat = kaml$Garden.Latitude
lon <- kaml$Garden.Longitude
df1 <- data.frame(lat, lon, as.character(kaml$Plant.ID))
mapImageData1 <- get_map(location = c(lon = -71.125, lat = 42.2996),
source = 'google',scale = 2,
zoom = 15, maptype = "satellite",
color = 'color')
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=42.2996,-71.125&zoom=15&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false
aa <- ggmap(mapImageData1) +
geom_point(data = df1, aes(x = lon, y = lat), size = 1, alpha= 0.7, color = 'red') +
#geom_text(data = df1, aes(x = lon, y = lat ,label = as.character.kaml.Plant.ID.),hjust=0, vjust=0, size = 2) +
scale_y_continuous(limits = c(42.2909, 42.308)) +
scale_x_continuous(limits = c(-71.135, -71.115)) +
labs(x = "Longitude", y = "Latitute")
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
## Scale for 'x' is already present. Adding another scale for 'x', which
## will replace the existing scale.
# add scalebar
sb <- data.frame(xmin = -71.122, xmax = -71.140, ymin = 42.291, ymax = 42.291)
sb$distance <- geosphere::distVincentyEllipsoid(c(sb$xmin,sb$ymin),
c(sb$xmax,sb$ymax))
scalebar.length <- 0.5
sb$lon.end <- sb$xmin - ((sb$xmax-sb$xmin)/sb$distance)*scalebar.length*1000
# pdf("~/Desktop/kalmiaMapLarge_legend.pdf", width = 9, height = 6)
aa + geom_segment(data = sb, aes(x = xmin, xend = lon.end, y = ymin, yend = ymax), color ="white", size = 2) +
geom_text(data = sb, aes(x = (lon.end + xmin) / 2, y = ymin + 0.0005,
label = paste(scalebar.length, "km")), inherit.aes=F, color = "white") +
geom_segment(data = sb, aes(x= -71.134, y = 42.306, xend = -71.134, yend = 42.3065),
arrow = arrow(length = unit(0.2, "cm")), size = 1.2,
color = 'white') +
geom_text(data = sb, aes(label = "N", x = -71.134, y = 42.306 -0.0003), inherit.aes=F, color = "white") +
geom_text(data = sb, aes(label = "Arnold Arboretum", x = -71.125, y = 42.299), inherit.aes=F, color = "white")
## Warning: Removed 1 rows containing missing values (geom_rect).
## Warning: Removed 1 rows containing missing values (geom_point).

#dev.off()
#ggsave(filename = "~/Desktop/kalmiaMapLarge_legend.png", width = 9, height = 6)
# make another map
mapImageData1 <- get_map(location = c(lon = -71.125 + 0.04, lat = 42.2996 + 0.04),
source = 'google',scale = 2,
zoom = 12, maptype = "satellite",
color = 'color')
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=42.3396,-71.085&zoom=12&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false
sb <- data.frame(xmin = -70.99, xmax = -71.10, ymin = 42.28, ymax = 42.28)
sb$distance <- geosphere::distVincentyEllipsoid(c(sb$xmin,sb$ymin),
c(sb$xmax,sb$ymax))
scalebar.length <- 5
sb$lon.end <- sb$xmin + ((sb$xmax-sb$xmin)/sb$distance)*scalebar.length*1000
ggmap(mapImageData1) +
geom_point(data = df1[1, ], aes(x = lon, y = lat), size = 2, color = 'white') +
geom_text(data = sb, aes(label = "Arnold Arboretum", x = -71.125, y = 42.299 + 0.002),
inherit.aes=F, color = "white") +
scale_y_continuous(limits = c(42.28, 42.4)) +
labs(x = "Longitude", y= "Latitude") +
geom_segment(data = sb, aes(x = xmin, xend = lon.end, y = ymin, yend = ymax), color ="white", size = 2) +
geom_text(data = sb, aes(x = (lon.end + xmin) / 2, y = ymin + 0.003,
label = paste(scalebar.length, "km")), inherit.aes=F, color = "white") +
geom_segment(data = sb, aes(x= -71.18, y = 42.395, xend = -71.18, yend = 42.400),
arrow = arrow(length = unit(0.2, "cm")), size = 1.2,
color = 'white') +
geom_text(data = sb, aes(label = "N", x = -71.18, y = 42.395 -0.002), inherit.aes=F, color = "white") +
geom_point(aes(y = 42.354389, x = -71.065539), color = "white", size = 2) +
geom_text(aes(y = 42.354389 + 0.003, x = -71.065539, label= "Boston Common"), color = 'white')
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
## Warning: Removed 1 rows containing missing values (geom_rect).

# ggsave(filename = "~/Desktop/BostonMap.png", width = 9, height = 6)